export default {
    data(){
        return{
            spanArr: {
                bpiType1: []
            },
            mergeField: [],
        }
    },
    methods: {
        /**
         * 合并
         * @param arr 需要合并的数组
         * @param id 需要合并的字段
         * @return 合并结果
         */
        merge(arr, id) {
            let spanArr = []
            let contactDot = 0;
            arr.forEach((item, index) => {
                if (index === 0) {
                    spanArr.push(1)
                } else {
                    if (item[id] === arr[index - 1][id] && item[id] && arr[index - 1][id]) {
                        spanArr[contactDot] += 1;
                        spanArr.push(0)
                    } else {
                        contactDot = index
                        spanArr.push(1)
                    }
                }
            })
            this.spanArr[id] =  spanArr;
        },
        //合并
        objectSpanMethod({row, column, rowIndex, columnIndex}) {
            if (columnIndex === 0 || columnIndex === 1  ||columnIndex === 2) {
                let n = this.mergeField[columnIndex]
                if (!n){
                    return {
                        rowspan: 1,
                        colspan: 1
                    }
                }
                if (this.spanArr[n][rowIndex]) {
                    return {
                        rowspan: this.spanArr[n][rowIndex],
                        colspan: 1
                    }
                } else {
                    return {
                        rowspan: 0,
                        colspan: 0
                    }
                }
            }
        }
    }
}